package gui;

import java.text.DecimalFormat;
import java.util.Random;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class rounding{
	
	/**
	 * Constructor that would generator a random number for the user
	 */
	private int e;
	private float a;
	private float o;
	
	public void rounding1(){
		
		Random num = new Random();
		
		a = num.nextFloat();
		a = a*(num.nextInt(10000));
		
		JOptionPane.showMessageDialog(null,
		    "Here is your random number: " + a,
		    "Random Number",
		    JOptionPane.PLAIN_MESSAGE);
		
		System.out.printf("Here: " + "%.10g%n",a);
		
		}
	
	public void rounding2(){
		Scanner reader = new Scanner(System.in);
		
		while(e <= 4){
			System.out.print("Enter a number from 1 to 4: " + "\n" +
							 "1: Tenths place: " + "\n" +
							 "2: Hundredths place: " + "\n" +
							 "3: Thousandths place: " + "\n" +
							 "4: TenThousandths place: "+ "\n" +
							 "5: Ones place: ");
			e = reader.nextInt();
				if(e == 1){
					System.out.printf("Please round this number to the nearest Tenths place:" + "%.10g%n",a);
					System.out.print("Enter your answer: ");
					o = reader.nextFloat();
				}
				else if(e == 2){
					System.out.printf("Please round this number to the nearest Hundredths place:" + "%.10g%n",a);
					System.out.print("Enter your answer: ");
					o = reader.nextFloat();
				}
				else if(e == 3){
					System.out.printf("Please round this number to the nearest Thousandths place:" + "%.10g%n",a);
					System.out.print("Enter your answer: ");
					o = reader.nextFloat();
				}
				else if(e==4){
					System.out.printf("Please round this number to the nearest TenThousandths place:" + "%.10g%n",a);
					System.out.print("Enter your answer: ");
					o = reader.nextFloat();
					break;
				}
				else if(e==5){
					System.out.printf("Please round this number to the nearest Ones place:" + "%.10g%n",a);
					System.out.print("Enter your answer: ");
					o = reader.nextFloat();
					break;
				}
				else if(e > 6
						){
					System.out.print("You didn't enter a number from 1 to four!");
					break;
				}
				else
					System.out.print("You didn't enter an number!");
				break;
		}
	}
	
	public void rounding3(){
		while(e != 0){
			if(e == 1){
				System.out.println("Please round to the nearest Tenths is selected for the question.");
				System.out.printf("The number that you rounded: " + "%.10g%n",a);
				System.out.printf("The number that you entered is: " + "%.5g%n",o);
				DecimalFormat de = new DecimalFormat("#.#");
				System.out.println("The correct answer is: " + de.format(a));
				break;
				}
			if(e==2){
				System.out.println("Please round to the nearest Hundredths is selected.");
				System.out.printf("The number that you rounded: " + "%.10g%n",a);
				System.out.printf("The number that you entered is: " + "%.6g%n",o);
				DecimalFormat de = new DecimalFormat("#.##");
				System.out.printf("The correct answer is: " + de.format(a));
				break;
				}
			if(e==3){
				System.out.println("Please round to the nearest Thousandths is selected.");
				System.out.printf("The number that you rounded: " + "%.10g%n",a);
				System.out.printf("The number that you entered is: " + "%.7g%n",o);
				DecimalFormat de = new DecimalFormat("#.###");
				System.out.printf("The correct answer is: " + de.format(a));
					break;
				}
			if(e==4){
				System.out.println("Please round to the nearest TenThousandths is selected.");
				System.out.printf("The number that you rounded: " + "%.10g%n",a);
				System.out.printf("The number that you entered is: " + "%.8g%n",o);
				DecimalFormat de = new DecimalFormat("#.####");
				System.out.printf("The correct answer is: " + de.format(a));
					break;
				}
			if(e==5){
				System.out.println("Please round to the nearest Ones is selected.");
				System.out.printf("The number that you rounded: " + "%.10g%n",a);
				System.out.printf("The number that you entered is: " + "%.8g%n",o);
				System.out.printf("The correct answer is: " + Math.rint(a));
					break;
				}
			}
		}
	}
		
	
